<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>刷卡数据获取任务管理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<jsp:include page="../resource.jsp"></jsp:include>
	<style type="text/css">
	  .input_text{ width:175px; border:1px solid #6D869E; vertical-align:middle; height:17px;}
	</style>
	<script type="text/javascript">
	$(document).ready(function() {
		var h = '85%';
 		if($.browser.msie && ($.browser.version == 8.0 || $.browser.version == 9.0)){
 	    	 h = $(self.parent.parent.frames['mainFrame']).height()-87; 
 	    }
        $('#cardtodevicegrid').omGrid({
        	dataSource : 'remoteOperator!findCardToDevice.do',
            height : h,
            limit : 20,
            showIndex : true,
            colModel : [ 
                        {header : '设备名称', name : 'objectName', width : 80, align : 'center'},
                         {header : 'GUID', name : 'guid', width : 100, align : 'center'},
                         {header : '任务执行方式', name : 'jobMode', width : 120, align : 'left' ,renderer : modelRenderer},
                         {header : '任务状态', name : 'jobStatus', width : 100, align : 'center',renderer : statusRenderer},
                         {header : '创建时间', name : 'createDatetime', width : 140, align : 'center'},
                         {header : '执行时间', name : 'startTime', width : 140, align : 'center'},
                         {header : '刷卡时间起', name : 'cardDatetime', width : 110, align : 'center',renderer : farmtDate},
                         {header : '刷卡时间止', name : 'cardDatetimeEnd', width : 110, align : 'center',renderer : farmtDate},
                         {header : '任务结束时间', name : 'finishDatetime', width : 140, align : 'center'},
                         {header : '启用状态', name : 'enable', width : 'autoExpand', align : 'left' ,renderer : stateRenderer}
                         ]
        });
        
        function farmtDate(value) {
        	if(value) {
        		return value.substring(0,10);
        	}else{
        		return "";
        	}
        }
        
    $('#cajobStatus').omCombo({
    	dataSource : 'upgrade!findJobStatus.do',
        onValueChange : function(target, newValue, oldValue) {
            $('#cajobStatusId').val(newValue);
        }
    });
    $('#cajobMode').omCombo({
    	dataSource : 'upgrade!findJobMode.do',
        onValueChange : function(target, newValue, oldValue) {
        	 $('#cajobModeId').val(newValue);
        }
    });
    
    $("#cardToDeviceEditor").omDialog({
    	    autoOpen: false,
		    height: 320,
		    width : 400,
		    modal: true,
		    buttons: [{
            text : "确定", 
            click : function () {
              $("#cardToDeviceForm").submit();
            }
         }, {
            text : "取消", 
            click : function () {
              $("#cardToDeviceEditor" ).omDialog("close");
          }
      }]
    });
        
    $('#addCardToDevice').click(function(){
    	$("#cardToDeviceEditor").omDialog('open');
    	$("#cardToDeviceForm").resetForm();
    });
    $('#deleteCardToDevice').click(function(){
    	var selects = $("#cardtodevicegrid").omGrid("getSelections",true);
    	if(selects.length <= 0){
    		$.omMessageBox.alert({content:'请您选择删除的记录'});
    		return;
    	}
    	 $.omMessageBox.confirm({
             title:'确认删除',
             content:'您确定删除该职务？',
             onClose:function(result){
            	 if(result){
            		 $.ajax({
            			 url : 'remoteOperator!deleteCardTD.do',
            	    	 data : {jobId : selects[0].id},
            			 success : function(data){
            				 if(data == '1'){
            					 $.omMessageTip.show({timeout : 2000,content : '删除成功！'});
            					 $('#cardtodevicegrid').omGrid("reload");
            				 }else{
            					 $.omMessageTip.show({timeout : 2000,content : '删除失败！'});
            				 }
            			 }
            		 });
            	 }
             }
         });
    });
    
    var options  = {
  		  url : 'remoteOperator!saveCardTD.do',
            success : function(data){
               	if(data == '1'){  
                   	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                   	$('#cardToDeviceEditor').omDialog('close');
                   	$('#cardtodevicegrid').omGrid("reload");
               	}else{
               		$.omMessageTip.show({timeout : 2000,content : '保存失败！',type : 'error'});
               	}
            }
  	  };
	  $('#cardToDeviceForm').submit(function() {
          $(this).omAjaxSubmit(options);
          return false;//返回false,阻止浏览器默认行为
    });
    
	function stateRenderer(v)
	{
		if(v){
			return "启用";
		}else{
			return "停用";
		}
	}
	
	function modelRenderer(v)
	{
		if(v == null) return "";
		return v.name;
	}
	function statusRenderer(v)
	{
		if(v == null) return "";
		return v.name;
	}
	if($('#cacardDatetime').next().attr('class') != 'om-calendar-trigger') {
	 	$('#cacardDatetime').omCalendar();
	}
	if($('#endDatetime').next().attr('class') != 'om-calendar-trigger') {
	 	$('#endDatetime').omCalendar();
	}
	
	if($('#cacardStartTime').next().attr('class') != 'om-calendar-trigger') {
	 	$('#cacardStartTime').omCalendar({showTime:true});
	}
	 	var tabId = self.parent.parent.frames['mainFrame'].$('#tabs').omTabs('getActivated');
		var s = "<script>function function_"+tabId+"(nodeData){$('#carefName').val(nodeData.text);"+
		"$('#carefId').val(nodeData.id);}<\/script>";
		$("#cardtodevicegrid").after(s);
	 
    });
	</script>  
  </head>
  
  <body>
    <div class="toolbar mar">
		         <a href="#" class="rbutton" id="addCardToDevice"><span><img src="../images/add.gif" width="14" height="14" /><ins>新增任务</ins></span></a>
		         <a  class="line"></A>
		         <a href="#" class="rbutton" id="deleteCardToDevice"><span><img src="../images/del.gif" width="14" height="14" /><ins>删除任务</ins></span></a>
	</div>
    <table id="cardtodevicegrid"></table>
    
    <div id="cardToDeviceEditor" title="编辑任务" style="display: none;">
     <form id="cardToDeviceForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
             <tr>
               <td width="30%" align="right">选择设备/终端：</td>
               <td width="68%" colspan="3">
                  <input type="hidden" id="carefId" name="catd.guid" />
                  <input type="text" id="carefName" class="input_text" value="在右侧菜单选择" readonly="readonly"/>
               </td>
             </tr>
             <tr>
               <td width="30%" align="right">是否启用：</td>
               <td width="68%" colspan="3">
                  <select id="enable" name="catd.enable" style="width: 175px">
                     <option value="true">启用</option>
                     <option value="false">停用</option>
                  </select>
               </td>
             </tr>
             <tr>
               <td width="30%" align="right">刷卡时间起：</td>
               <td width="68%" colspan="3">
                  <input type="text" id="cacardDatetime" name="catd.cardDatetime">
               </td>
             </tr>
             <tr>
             	<td width="30%" align="right">刷卡时间止</td>
               	<td width="68%" colspan="3">
                  <input type="text" id="endDatetime" name="catd.cardDatetimeEnd">
               </td>
             </tr>
             <tr>
               <td width="30%" align="right">任务执行方式：</td>
               <td width="68%" colspan="3">
                  <input id="cajobMode" name="jobMode">
                  <input id="cajobModeId" name="jobModeId" type="hidden">
               </td>
             </tr>
             <tr>
               <td width="30%" align="right">任务执行时间：</td>
               <td width="68%" colspan="3">
                  <input type="text" id="cacardStartTime" name="catd.startTime">
               </td>
             </tr>
           </table>
         </form>
   </div>
  </body>
</html>
